import Vue from 'vue'
import Router from 'vue-router'
import approvalsRouter from './modules/approvals'
import departmentsRouter from './modules/departments'
import employeesRouter from './modules/employees'
import permissionRouter from './modules/permission'
import attendancesRouter from './modules/attendances'
import salarysRouter from './modules/salarys'
import settingRouter from './modules/setting'
import socialRouter from './modules/social'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/map', // 路径
    name: 'map', // 给路由规则加一个name
    component: Layout, // 组件
    children: [{
      path: '',
      component: () => import('@/views/map'),
      meta: {
        title: '地图',
        icon: 'people'
      }
    }]
  },
  {
    path: '/echarts', // 路径
    name: 'echarts', // 给路由规则加一个name
    component: Layout, // 组件
    children: [{
      path: '', // 这里当二级路由的path什么都不写的时候 表示该路由为当前二级路由的默认路由
      component: () => import('@/views/echarts'),
      meta: {
        title: '大屏',
        icon: 'people'
      }
    }]
  },
  {
    path: '/import', // 路径
    name: 'import', // 给路由规则加一个name
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/import'),
      meta: {
        title: '导入',
        icon: 'people'
      }
    }],
    hidden: true
  }
  // 404 page must be placed at the end !!!
//   { path: '*', redirect: '/404', hidden: true }
]
export const asyncRoutes = [
  approvalsRouter,
  departmentsRouter,
  employeesRouter,
  permissionRouter,
  attendancesRouter,
  salarysRouter,
  settingRouter,
  socialRouter

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  //   routes: [...constantRoutes, ...asyncRoutes]
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
